package cn.assumejson.springframework.aop.framework;

import cn.assumejson.springframework.aop.aspectj.AopProxy;
import cn.assumejson.springframework.aop.aspectj.Cglib2AopProxy;
import cn.assumejson.springframework.aop.aspectj.JdkDynamicAopProxy;

/**
 * 代理工厂
 *
 * @author Mr. Li
 * @version 1.0
 * @since 1.0 2021/12/2 15:18
 */
public class ProxyFactory {
    private AdvisedSupport advisedSupport;

    public ProxyFactory(AdvisedSupport advisedSupport) {
        this.advisedSupport = advisedSupport;
    }

    public Object getProxy() {
        return createAopProxy().getProxy();
    }

    private AopProxy createAopProxy() {
        if (advisedSupport.isProxyTargetClass()) {
            return new Cglib2AopProxy(advisedSupport);
        }
        return new JdkDynamicAopProxy(advisedSupport);
    }
}
